package com.calmcar.adas.apiserver.view;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.util.AttributeSet;
import android.view.TextureView;

import com.calmcar.adas.apiserver.AdasConf;
import com.calmcar.adas.apiserver.model.CdwDetectInfo;
import com.calmcar.adas.apiserver.model.LdwDetectInfo;

/**
 * 绘制视图
 */

public abstract  class AdasDrawView extends TextureView implements TextureView.SurfaceTextureListener {
    float mScale;

    public AdasDrawView(Context context) {
        this(context, null);
    }

    public AdasDrawView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AdasDrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setOpaque(false);//设置背景透明，记住这里是[是否不透明]
        setSurfaceTextureListener(this);//设置监听
    }


    public  void  initScale(int width ,int height ){
        if(AdasConf.IN_FRAME_HEIGHT>0){
            mScale = Math.min(((float)height)/AdasConf.IN_FRAME_HEIGHT, ((float)width)/AdasConf.IN_FRAME_WIDTH);
        }else{
            mScale = 0;
        }
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        //当TextureView初始化时调用，事实上当你的程序退到后台它会被销毁，你再次打开程序的时候它会被重新初始化
        initScale(width ,height);
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        //当TextureView的大小改变时调用
        initScale(width ,height);
    }

    public abstract  void drawBitmap(LdwDetectInfo ldwDetectInfo, CdwDetectInfo cdwDetectInfo);

}
